<?php
$hostname = "remote-mysql4.servage.net"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost
$db_user = "ntnu"; // change to your database password
$db_password = "fotball123"; // change to your database password
$database = "ntnu"; // provide your database name


# STOP HERE
####################################################################
# THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE
$db = mysql_connect($hostname, $db_user, $db_password);

if (!$db)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db($database,$db);

if (!isset($_SESSION['brukertype']))
{
}
else
{
	if($_SESSION['brukertype']>2)
	{
?>


	<script type="text/javascript" src="../nicedit/nicEdit.js"> </script> <script type="text/javascript">
	//<![CDATA[
	bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
	//]]>
	</script>
	<form method="post" action="">
	Tittel: <input name="overskrift" id="overskrift" type="text" />
	<textarea name="area1" cols="65" rows="10"></textarea><br />
	Bilde: <input name="imageupload" id="imageupload" type="file" /><br />Publisert av: <input name="publisertav" id="publisertav" type="text"/>
    <br /><br />
    <input type="submit" VALUE="Lagre" name="Submit">
    </form>    
 
<? 
	//Kode for å utføre handlinger når Lagre-knappen er trykket
  
		if (isset($_REQUEST['Submit'])) 
		{

		$sql="INSERT INTO nyheter (overskrift, dato, innhold, publisertav, bilde) VALUES ('$_POST[overskrift]', NOW(), '$_POST[area1]', '$_POST[publisertav]', '$_POST[imageupload]')";


			if($result = mysql_query($sql ,$db)) 
			{
			echo 'Lagret!';
			}

			else 
			{
			echo "ERROR: ".mysql_error();
			}
		}
 
		else 
		{
		// DISPLAY FORM IF FORM HAS NOT BEEN SUBMITTED
		}

	}
	
	else
	{
		echo "Du kan ikke legge ut nyheter. Kontakt administrator";	
	}
		
}
?>